package org.jspresso.framework.application.frontend.action.entity.clone;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.jspresso.framework.application.backend.persistence.hibernate.HibernateBackendController;
import org.jspresso.framework.application.frontend.action.std.EditComponentAction;
import org.jspresso.model.ActionTestInput;
import org.jspresso.model.ActionTestIo;
import org.jspresso.model.TestEntity;
import org.jspresso.model.TestEntityPicker;

public class ChooseEntityToCloneAction<E,F,G> extends EditComponentAction<E,F,G> {

	@Override
	protected Object getComponentToEdit(Map<String, Object> context) {
//		// This is heavily view dependent
//		Collection<ActionTestInput> inputs = getModel(new int[]{-5,1,0}, context);
//		if(inputs == null) { // We are called from another part of the view
//			inputs = getModel(new int[]{-4, 1, 0}, context);
//		}
		
		List<TestEntity> refEntities = ((ActionTestIo)getParentModel(context)).getBackActionTest().getTestScope().retrieveScopeContent((HibernateBackendController) getBackendController(context));

		
//		for(ActionTestInput input : inputs) {
//			if(ActionTestInput.PARAMETER_TYPE_REF.equals(input.getParameterType()) && input.getParameterRefValue() != null) {
//				refEntities.add(input.getParameterRefValue());
//			}
//		}
		
		TestEntityPicker picker = getBackendController(context).getEntityFactory().createComponentInstance(TestEntityPicker.class);
		picker.setTestEntities(refEntities);
		return picker;
	}
	
}
